package com.fenghongzhang.module_home.ui.recommend.movie

import androidx.lifecycle.ViewModel
import com.fenghongzhang.lib_base.core.BaseViewModel
import com.fenghongzhang.module_home.HomeUIState
import com.fenghongzhang.module_home.model.RecommendMutilVideo
import com.fenghongzhang.module_home.ui.recommend.RecommendIntent
import com.fenghongzhang.module_home.ui.recommend.RecommendRepository
import com.fenghongzhang.module_home.ui.recommend.RecommendUIState
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class RecommendViewModel @Inject constructor(val repository: RecommendRepository): BaseViewModel<RecommendUIState, RecommendIntent>(RecommendUIState()) {

    override suspend fun handleEvent(event: RecommendIntent) {
        when (event) {
            is RecommendIntent.LoadData -> loadData()
            is RecommendIntent.LoadMore -> loadMore()
            is RecommendIntent.Refresh -> refresh()
            is RecommendIntent.ClickItem -> clickItem(event.item)
        }
    }

    private fun clickItem(item: RecommendMutilVideo) {

    }

    private fun refresh() {

    }

    private fun loadMore() {

    }

    private suspend fun loadData() {
        val res =  repository.getRecyclerviewData()
        res.onSuccess {
            updateState(RecommendUIState(recommendMutilVideo = it.recommendMutilVideo,  isSucess = true))
        }.onFailure {

        }
    }


}